package generatedClasses;

import java.util.*;
import struts.*;
import struts.tools.*;

public class ContactValidationCreator
{
  protected static String nl;
  public static synchronized ContactValidationCreator create(String lineSeparator)
  {
    nl = lineSeparator;
    ContactValidationCreator result = new ContactValidationCreator();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = NL;
  protected final String TEXT_3 = NL;
  protected final String TEXT_4 = NL;
  protected final String TEXT_5 = NL;
  protected final String TEXT_6 = NL;
  protected final String TEXT_7 = NL;
  protected final String TEXT_8 = NL;
  protected final String TEXT_9 = NL + NL + "\t";
  protected final String TEXT_10 = NL + "\t\tprivate String ";
  protected final String TEXT_11 = " = null;\t" + NL + "\t";
  protected final String TEXT_12 = NL + "\t" + NL + "\t";
  protected final String TEXT_13 = NL + "\t" + NL + "\t\tpublic String get";
  protected final String TEXT_14 = "(){" + NL + "\t\t\treturn ";
  protected final String TEXT_15 = ";" + NL + "\t\t}" + NL + "\t";
  protected final String TEXT_16 = NL + NL + "\t";
  protected final String TEXT_17 = NL + "\t\tpublic void set";
  protected final String TEXT_18 = "(String string){" + NL + "\t\t\t\t";
  protected final String TEXT_19 = "=string;" + NL + "\t\t}\t" + NL + "\t";
  protected final String TEXT_20 = NL + "\t" + NL + "\t";
  protected final String TEXT_21 = NL + "\t\t ";
  protected final String TEXT_22 = NL + "\t\t" + NL + "\t\t\t\tthis.";
  protected final String TEXT_23 = "=null;" + NL + "\t\t";
  protected final String TEXT_24 = NL + "\t  }" + NL + "\t";
  protected final String TEXT_25 = "      " + NL + "\t\t";
  protected final String TEXT_26 = NL + "\t" + NL + "\t\t";
  protected final String TEXT_27 = NL + "\t\t\t";
  protected final String TEXT_28 = NL + "\t\t\t\t" + NL + "\t\t";
  protected final String TEXT_29 = "  \t  " + NL + "\t}\t  ";
  protected final String TEXT_30 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     ArrayList<DataElement> formElts = (ArrayList<DataElement>) argument; 

    stringBuffer.append(TEXT_1);
    stringBuffer.append( "package struts.actionForm;" );
    stringBuffer.append(TEXT_2);
    stringBuffer.append( "import javax.servlet.http.HttpServletRequest;");
    stringBuffer.append(TEXT_3);
    stringBuffer.append( "import org.apache.struts.action.ActionErrors;");
    stringBuffer.append(TEXT_4);
    stringBuffer.append( "import org.apache.struts.action.ActionForm;");
    stringBuffer.append(TEXT_5);
    stringBuffer.append( "import org.apache.struts.action.ActionMapping;");
    stringBuffer.append(TEXT_6);
    stringBuffer.append( "import org.apache.struts.action.ActionMessage;");
    stringBuffer.append(TEXT_7);
    stringBuffer.append( "public class AddContactValidationForm extends ActionForm {" );
    stringBuffer.append(TEXT_8);
    stringBuffer.append( "private static final long serialVersionUID = 1L;" );
    stringBuffer.append(TEXT_9);
    	for(DataElement de:formElts){ 
    stringBuffer.append(TEXT_10);
    stringBuffer.append(de.getName().replaceAll("[ ]",""));
    stringBuffer.append(TEXT_11);
    }
    stringBuffer.append(TEXT_12);
    for(DataElement de:formElts){ 
    stringBuffer.append(TEXT_13);
    stringBuffer.append(de.getName().replaceAll("[ ]",""));
    stringBuffer.append(TEXT_14);
    stringBuffer.append(de.getName().replaceAll("[ ]",""));
    stringBuffer.append(TEXT_15);
    }
    stringBuffer.append(TEXT_16);
    for(DataElement de:formElts){ 
    stringBuffer.append(TEXT_17);
    stringBuffer.append(de.getName().replaceAll("[ ]",""));
    stringBuffer.append(TEXT_18);
    stringBuffer.append(de.getName().replaceAll("[ ]",""));
    stringBuffer.append(TEXT_19);
    }
    stringBuffer.append(TEXT_20);
    stringBuffer.append( "public void reset(ActionMapping mapping, HttpServletRequest request) {");
    stringBuffer.append(TEXT_21);
    for(DataElement de:formElts){ 
    stringBuffer.append(TEXT_22);
    stringBuffer.append(de.getName().replaceAll("[ ]",""));
    stringBuffer.append(TEXT_23);
    }
    stringBuffer.append(TEXT_24);
    stringBuffer.append( "public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) {");
    stringBuffer.append(TEXT_25);
    Validation v=new Validation();
    stringBuffer.append(TEXT_26);
    for(DataElement de:formElts){ 
    stringBuffer.append(TEXT_27);
    stringBuffer.append(v.generateTest(de));
    stringBuffer.append(TEXT_28);
    }
    stringBuffer.append(TEXT_29);
    stringBuffer.append(TEXT_30);
    return stringBuffer.toString();
  }
}
